<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="上级wbs_id" prop="parentWbsId">
        <el-input
          v-model="queryParams.parentWbsId"
          placeholder="请输入上级wbs_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同id" prop="contractId">
        <el-input
          v-model="queryParams.contractId"
          placeholder="请输入合同id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="wbs编号" prop="wbsBh">
        <el-input
          v-model="queryParams.wbsBh"
          placeholder="请输入wbs编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="wbs名称" prop="wbsMc">
        <el-input
          v-model="queryParams.wbsMc"
          placeholder="请输入wbs名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['jl_base:baseBaWbs:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['jl_base:baseBaWbs:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['jl_base:baseBaWbs:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['jl_base:baseBaWbs:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseBaWbsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="wbs主键" align="center" prop="wbsId" v-if="true"/>
      <el-table-column label="上级wbs_id" align="center" prop="parentWbsId" />
      <el-table-column label="合同id" align="center" prop="contractId" />
      <el-table-column label="是否允许修改flag" align="center" prop="updateFlag" />
      <el-table-column label="审核状态" align="center" prop="approveFlag" />
      <el-table-column label="系统编号" align="center" prop="xtbh" />
      <el-table-column label="wbs编号" align="center" prop="wbsBh" />
      <el-table-column label="wbs名称" align="center" prop="wbsMc" />
      <el-table-column label="wbs全称" align="center" prop="wbsQcl" />
      <el-table-column label="工程量清单id" align="center" prop="sheetId" />
      <el-table-column label="子目号(冗余)" align="center" prop="zmh" />
      <el-table-column label="wbs初始数量" align="center" prop="wbsCsNum" />
      <el-table-column label="wbs初始复核数量" align="center" prop="wbsCsFhNum" />
      <el-table-column label="wbs清单数量变化" align="center" prop="wbsNumBg" />
      <el-table-column label="wbs导入时清单初始单价(从工程量清单中读取)" align="center" prop="sheetCsPrice" />
      <el-table-column label="清单单价变化(与工程量清单共享)" align="center" prop="sheetPriceBg" />
      <el-table-column label="清单实时单价(从工程量清单中读取)" align="center" prop="sheetSsPrice" />
      <el-table-column label="wbs清单初始总价(wbs初始复核数量xwbs导入时清单初始单价)" align="center" prop="wbsCsTotalMoney" />
      <el-table-column label="wbs清单实时数量(=wbs初始复核数量+wbs清单数量变化)" align="center" prop="wbsSsNum" />
      <el-table-column label="wbs清单实时总价(=wbs清单实时数量x清单实时单价)" align="center" prop="wbsSsTotalMoney" />
      <el-table-column label="wbs清单总价变化(=wbs清单实时总价-wbs清单初始总价)" align="center" prop="wbsTatalMoneyBg" />
      <el-table-column label="wbs清单初始部分累计计量数量" align="center" prop="wbsCsHavaJlNum" />
      <el-table-column label="wbs清单初始部分累计计量金额(=清单初始部分累计计量数量x清单实时单价)" align="center" prop="wbsCsHaveJlTotalMoney" />
      <el-table-column label="wbs清单变更部分累计计量数量" align="center" prop="wbsBgHavaJlNum" />
      <el-table-column label="wbs清单变更部分累计计量金额(=wbs清单变更部分累计计量数量x清单实时单价)" align="center" prop="wbsBgHaveJlTotalMoney" />
      <el-table-column label="wbs清单累计计量数量(=wbs清单初始部分累计计量数量+wbs清单变更部分累计计量数量)" align="center" prop="wbsHaveJlNum" />
      <el-table-column label="wbs清单累计计量金额(=wbs清单累计计量数量x清单实时单价)" align="center" prop="wbsHaveJlTotalMoney" />
      <el-table-column label="wbs清单初始部分计量审批中数量" align="center" prop="wbsCsJlSpzNum" />
      <el-table-column label="wbs初始部分可计量数量(=wbs清单初始复核数量-wbs清单初始部分累计计量数量-wbs清单初始部分计量审批中数量)" align="center" prop="wbsCsCouldJlNum" />
      <el-table-column label="wbs清单变更部分计量审批中数量" align="center" prop="wbsBgJlSpzNum" />
      <el-table-column label="wbs变更部分可计量数量(=wbs清单数量变化-wbs清单变更部分累计计量数量-wbs清单变更部分计量审批中数量)" align="center" prop="wbsBgCouldJlNum" />
      <el-table-column label="wbs清单实时可计量数量(=wbs变更部分可计量数量+wbs初始部分可计量数量)" align="center" prop="wbsSsCouldJlNum" />
      <el-table-column label="合同图号" align="center" prop="htth" />
      <el-table-column label="计算式" align="center" prop="jss" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['jl_base:baseBaWbs:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['jl_base:baseBaWbs:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改wbs清单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="上级wbs_id" prop="parentWbsId">
          <el-input v-model="form.parentWbsId" placeholder="请输入上级wbs_id" />
        </el-form-item>
        <el-form-item label="合同id" prop="contractId">
          <el-input v-model="form.contractId" placeholder="请输入合同id" />
        </el-form-item>
        <el-form-item label="是否允许修改flag" prop="updateFlag">
          <el-input v-model="form.updateFlag" placeholder="请输入是否允许修改flag" />
        </el-form-item>
        <el-form-item label="审核状态" prop="approveFlag">
          <el-input v-model="form.approveFlag" placeholder="请输入审核状态" />
        </el-form-item>
        <el-form-item label="系统编号" prop="xtbh">
          <el-input v-model="form.xtbh" placeholder="请输入系统编号" />
        </el-form-item>
        <el-form-item label="wbs编号" prop="wbsBh">
          <el-input v-model="form.wbsBh" placeholder="请输入wbs编号" />
        </el-form-item>
        <el-form-item label="wbs名称" prop="wbsMc">
          <el-input v-model="form.wbsMc" placeholder="请输入wbs名称" />
        </el-form-item>
        <el-form-item label="wbs全称" prop="wbsQcl">
          <el-input v-model="form.wbsQcl" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工程量清单id" prop="sheetId">
          <el-input v-model="form.sheetId" placeholder="请输入工程量清单id" />
        </el-form-item>
        <el-form-item label="子目号(冗余)" prop="zmh">
          <el-input v-model="form.zmh" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="wbs初始数量" prop="wbsCsNum">
          <el-input v-model="form.wbsCsNum" placeholder="请输入wbs初始数量" />
        </el-form-item>
        <el-form-item label="wbs初始复核数量" prop="wbsCsFhNum">
          <el-input v-model="form.wbsCsFhNum" placeholder="请输入wbs初始复核数量" />
        </el-form-item>
        <el-form-item label="wbs清单数量变化" prop="wbsNumBg">
          <el-input v-model="form.wbsNumBg" placeholder="请输入wbs清单数量变化" />
        </el-form-item>
        <el-form-item label="wbs导入时清单初始单价(从工程量清单中读取)" prop="sheetCsPrice">
          <el-input v-model="form.sheetCsPrice" placeholder="请输入wbs导入时清单初始单价(从工程量清单中读取)" />
        </el-form-item>
        <el-form-item label="清单单价变化(与工程量清单共享)" prop="sheetPriceBg">
          <el-input v-model="form.sheetPriceBg" placeholder="请输入清单单价变化(与工程量清单共享)" />
        </el-form-item>
        <el-form-item label="清单实时单价(从工程量清单中读取)" prop="sheetSsPrice">
          <el-input v-model="form.sheetSsPrice" placeholder="请输入清单实时单价(从工程量清单中读取)" />
        </el-form-item>
        <el-form-item label="wbs清单初始总价(wbs初始复核数量xwbs导入时清单初始单价)" prop="wbsCsTotalMoney">
          <el-input v-model="form.wbsCsTotalMoney" placeholder="请输入wbs清单初始总价(wbs初始复核数量xwbs导入时清单初始单价)" />
        </el-form-item>
        <el-form-item label="wbs清单实时数量(=wbs初始复核数量+wbs清单数量变化)" prop="wbsSsNum">
          <el-input v-model="form.wbsSsNum" placeholder="请输入wbs清单实时数量(=wbs初始复核数量+wbs清单数量变化)" />
        </el-form-item>
        <el-form-item label="wbs清单实时总价(=wbs清单实时数量x清单实时单价)" prop="wbsSsTotalMoney">
          <el-input v-model="form.wbsSsTotalMoney" placeholder="请输入wbs清单实时总价(=wbs清单实时数量x清单实时单价)" />
        </el-form-item>
        <el-form-item label="wbs清单总价变化(=wbs清单实时总价-wbs清单初始总价)" prop="wbsTatalMoneyBg">
          <el-input v-model="form.wbsTatalMoneyBg" placeholder="请输入wbs清单总价变化(=wbs清单实时总价-wbs清单初始总价)" />
        </el-form-item>
        <el-form-item label="wbs清单初始部分累计计量数量" prop="wbsCsHavaJlNum">
          <el-input v-model="form.wbsCsHavaJlNum" placeholder="请输入wbs清单初始部分累计计量数量" />
        </el-form-item>
        <el-form-item label="wbs清单初始部分累计计量金额(=清单初始部分累计计量数量x清单实时单价)" prop="wbsCsHaveJlTotalMoney">
          <el-input v-model="form.wbsCsHaveJlTotalMoney" placeholder="请输入wbs清单初始部分累计计量金额(=清单初始部分累计计量数量x清单实时单价)" />
        </el-form-item>
        <el-form-item label="wbs清单变更部分累计计量数量" prop="wbsBgHavaJlNum">
          <el-input v-model="form.wbsBgHavaJlNum" placeholder="请输入wbs清单变更部分累计计量数量" />
        </el-form-item>
        <el-form-item label="wbs清单变更部分累计计量金额(=wbs清单变更部分累计计量数量x清单实时单价)" prop="wbsBgHaveJlTotalMoney">
          <el-input v-model="form.wbsBgHaveJlTotalMoney" placeholder="请输入wbs清单变更部分累计计量金额(=wbs清单变更部分累计计量数量x清单实时单价)" />
        </el-form-item>
        <el-form-item label="wbs清单累计计量数量(=wbs清单初始部分累计计量数量+wbs清单变更部分累计计量数量)" prop="wbsHaveJlNum">
          <el-input v-model="form.wbsHaveJlNum" placeholder="请输入wbs清单累计计量数量(=wbs清单初始部分累计计量数量+wbs清单变更部分累计计量数量)" />
        </el-form-item>
        <el-form-item label="wbs清单累计计量金额(=wbs清单累计计量数量x清单实时单价)" prop="wbsHaveJlTotalMoney">
          <el-input v-model="form.wbsHaveJlTotalMoney" placeholder="请输入wbs清单累计计量金额(=wbs清单累计计量数量x清单实时单价)" />
        </el-form-item>
        <el-form-item label="wbs清单初始部分计量审批中数量" prop="wbsCsJlSpzNum">
          <el-input v-model="form.wbsCsJlSpzNum" placeholder="请输入wbs清单初始部分计量审批中数量" />
        </el-form-item>
        <el-form-item label="wbs初始部分可计量数量(=wbs清单初始复核数量-wbs清单初始部分累计计量数量-wbs清单初始部分计量审批中数量)" prop="wbsCsCouldJlNum">
          <el-input v-model="form.wbsCsCouldJlNum" placeholder="请输入wbs初始部分可计量数量(=wbs清单初始复核数量-wbs清单初始部分累计计量数量-wbs清单初始部分计量审批中数量)" />
        </el-form-item>
        <el-form-item label="wbs清单变更部分计量审批中数量" prop="wbsBgJlSpzNum">
          <el-input v-model="form.wbsBgJlSpzNum" placeholder="请输入wbs清单变更部分计量审批中数量" />
        </el-form-item>
        <el-form-item label="wbs变更部分可计量数量(=wbs清单数量变化-wbs清单变更部分累计计量数量-wbs清单变更部分计量审批中数量)" prop="wbsBgCouldJlNum">
          <el-input v-model="form.wbsBgCouldJlNum" placeholder="请输入wbs变更部分可计量数量(=wbs清单数量变化-wbs清单变更部分累计计量数量-wbs清单变更部分计量审批中数量)" />
        </el-form-item>
        <el-form-item label="wbs清单实时可计量数量(=wbs变更部分可计量数量+wbs初始部分可计量数量)" prop="wbsSsCouldJlNum">
          <el-input v-model="form.wbsSsCouldJlNum" placeholder="请输入wbs清单实时可计量数量(=wbs变更部分可计量数量+wbs初始部分可计量数量)" />
        </el-form-item>
        <el-form-item label="合同图号" prop="htth">
          <el-input v-model="form.htth" placeholder="请输入合同图号" />
        </el-form-item>
        <el-form-item label="计算式" prop="jss">
          <el-input v-model="form.jss" placeholder="请输入计算式" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBaseBaWbs, getBaseBaWbs, delBaseBaWbs, addBaseBaWbs, updateBaseBaWbs } from "@/api/jl_base/baseBaWbs";

export default {
  name: "BaseBaWbs",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // wbs清单表格数据
      baseBaWbsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        parentWbsId: undefined,
        contractId: undefined,
        wbsBh: undefined,
        wbsMc: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        parentWbsId: [
          { required: true, message: "上级wbs_id不能为空", trigger: "blur" }
        ],
        contractId: [
          { required: true, message: "合同id不能为空", trigger: "blur" }
        ],
        wbsBh: [
          { required: true, message: "wbs编号不能为空", trigger: "blur" }
        ],
        wbsMc: [
          { required: true, message: "wbs名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询wbs清单列表 */
    getList() {
      this.loading = true;
      listBaseBaWbs(this.queryParams).then(response => {
        this.baseBaWbsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        wbsId: undefined,
        parentWbsId: undefined,
        contractId: undefined,
        updateFlag: undefined,
        approveFlag: undefined,
        xtbh: undefined,
        wbsBh: undefined,
        wbsMc: undefined,
        wbsQcl: undefined,
        sheetId: undefined,
        zmh: undefined,
        wbsCsNum: undefined,
        wbsCsFhNum: undefined,
        wbsNumBg: undefined,
        sheetCsPrice: undefined,
        sheetPriceBg: undefined,
        sheetSsPrice: undefined,
        wbsCsTotalMoney: undefined,
        wbsSsNum: undefined,
        wbsSsTotalMoney: undefined,
        wbsTatalMoneyBg: undefined,
        wbsCsHavaJlNum: undefined,
        wbsCsHaveJlTotalMoney: undefined,
        wbsBgHavaJlNum: undefined,
        wbsBgHaveJlTotalMoney: undefined,
        wbsHaveJlNum: undefined,
        wbsHaveJlTotalMoney: undefined,
        wbsCsJlSpzNum: undefined,
        wbsCsCouldJlNum: undefined,
        wbsBgJlSpzNum: undefined,
        wbsBgCouldJlNum: undefined,
        wbsSsCouldJlNum: undefined,
        htth: undefined,
        jss: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.wbsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加wbs清单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const wbsId = row.wbsId || this.ids
      getBaseBaWbs(wbsId).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改wbs清单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.wbsId != null) {
            updateBaseBaWbs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addBaseBaWbs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const wbsIds = row.wbsId || this.ids;
      this.$modal.confirm('是否确认删除wbs清单编号为"' + wbsIds + '"的数据项？').then(() => {
        this.loading = true;
        return delBaseBaWbs(wbsIds);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('jl_base/baseBaWbs/export', {
        ...this.queryParams
      }, `baseBaWbs_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
